//
//  ViewController.m
//  CitySelect
//
//  Created by 李成鹏 on 16/8/16.
//  Copyright © 2016年 MorpLCP. All rights reserved.
//

#import "ViewController.h"
#import "SelectCityViewController.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
    btn.frame = CGRectMake(0, 250, self.view.frame.size.width, 40);
    btn.tag = 800841;
    NSString *cityName = [[NSUserDefaults standardUserDefaults] objectForKey:@"currentCity"];
    if (cityName == nil || [cityName isEqualToString:@""]) {
        [btn setTitle:@"未定位到城市" forState:(UIControlStateNormal)];
    } else {
        [btn setTitle:cityName forState:(UIControlStateNormal)];
    }
    [btn addTarget:self action:@selector(goSelectCity) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:btn];
}

- (void)goSelectCity {
    SelectCityViewController *cityVC = [SelectCityViewController new];
    cityVC.selectOK = ^() {
        UIButton *btn = (UIButton *)[self.view viewWithTag:800841];
        NSString *cityName = [[NSUserDefaults standardUserDefaults] objectForKey:@"currentCity"];
        [btn setTitle:cityName forState:(UIControlStateNormal)];
    };
    [self.navigationController pushViewController:cityVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
